﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Windows.Threading;    //多线程

namespace EventSample
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            DispatcherTimer timer = new DispatcherTimer();  //实例化Timer
            timer.Interval = TimeSpan.FromSeconds(1);   //一秒生成一次
            timer.Tick += Timer_Tick;
            //当计时器到达指定的时间间隔时，就会触发这个 Tick 事件，然后执行 Timer_Tick 方法。
            timer.Start();      //使能Timer实例
        }

        //Timer_Tick 方法。
        private void Timer_Tick(object? sender, EventArgs e)
        {
            this.TextBoxTime.Text = DateTime.Now.ToString();
        }

    }
}